package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.system.SystemAreaBo;
import com.cw.jeeyt.dao.model.system.SystemAreaDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 中国区域转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemAreaConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemAreaBo do2Bo(SystemAreaDo model) {
        if (model == null) {
            return null;
        }
        SystemAreaBo bo = new SystemAreaBo();
        bo.setId(model.getId());
        bo.setCityId(model.getCityId());
        bo.setAreaCode(model.getAreaCode());
        bo.setAreaName(model.getAreaName());
        bo.setComment(model.getComment());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemAreaDo bo2Do(SystemAreaBo bo) {
        if (bo == null) {
            return null;
        }
        SystemAreaDo model = new SystemAreaDo();
        model.setId(bo.getId());
        model.setCityId(bo.getCityId());
        model.setAreaCode(bo.getAreaCode());
        model.setAreaName(bo.getAreaName());
        model.setComment(bo.getComment());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemAreaBo> doList2BoList(List<SystemAreaDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemAreaConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemAreaDo> boList2DoList(List<SystemAreaBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemAreaConverter::bo2Do));
    }
}